#include "stdafx.h"
#include "GoogleEntry.h"

#define _GOOGLE_DLL_EXPORT
#include "GoogleAPI.h"

using namespace GoogleProtocol;



BOOL WINAPI DllMain(
  HANDLE hinstDLL, 
  DWORD dwReason, 
  LPVOID lpvReserved
)
{
	return TRUE;
}

//-------------------------------------------------------------------
//  Description:      Auto Release Memory Class.
//
//-------------------------------------------------------------------
class CAutoReleaseMemory
{
public:
	~CAutoReleaseMemory(){ CGoogleEntry::FreeInstance(); }
};

// Golobal and unique object.
static const CAutoReleaseMemory _AutoReleaseMemory;

//-------------------------------------------------------------------
//  Description:      Login to google server.
//
//  Parameter:
//      lpUserName:   User Account.
//      lpPassword:   User Password.
//
//  Return:
//       1            Succeed.
//       0            Failed.
//      -1            Http request error;
//      -2            Authorization error.
//      -3            Account Id or password error.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT LogIn(LPCSTR lpUserName, LPCSTR lpPassword)
{
	return CGoogleEntry::GetInstance()->LogIn(lpUserName, lpPassword);
}

//-------------------------------------------------------------------
//  Description:     Logout from google server.
//
//  Parameter:
//
//  Return:
//      1            Succeed.
//      0            Failed.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT LogOut()
{
	return CGoogleEntry::GetInstance()->LogOut();
}

//-------------------------------------------------------------------
//  Description:      Set server ip address to google contact.
//
//  Parameter:
//      lpEntryName:  Server's name.
//      lpIPAddr:     New server' ip address.
//
//  Return:
//       2            Created succeed.
//       1            Updated succeed.
//       0            Failed.
//      -1            Http request error;
//      -2            Authorization error.
//      -3            Account Id or password error.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT SetIP(LPCSTR lpEntryName, LPCSTR lpIPAddr)
{
	return CGoogleEntry::GetInstance()->SetIP(lpEntryName, lpIPAddr);
}

//-------------------------------------------------------------------
//  Description:      Get server ip address from google contact.
//
//  Parameter:
//      lpEntryName:  Server's name.
//      lpIPAddr:     Receives server' ip address.
//
//  Return:
//       1            Succeed.
//       0            Failed.
//      -1            Http request error;
//      -2            Authorization error.
//      -3            Account Id or password error.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT GetIP(LPCSTR lpEntryName, LPSTR lpIPAddr)
{
	return CGoogleEntry::GetInstance()->GetIP(lpEntryName, lpIPAddr);
}

//-------------------------------------------------------------------
//  Description:     Get user name
//
//  Parameter:
//                   [OUT] user name
//  Return:
//      1            Succeed.
//      0            Failed.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT GetAccountId(LPWSTR lpUserName)
{
	return CGoogleEntry::GetInstance()->GetUserName(lpUserName);
}

//-------------------------------------------------------------------
//  Description:     Get user password
//
//  Parameter:
//                   [OUT] user password
//  Return:
//      1            Succeed.
//      0            Failed.
//-------------------------------------------------------------------
GOOGLE_EXPORT LRESULT GetAccountPwd(LPWSTR lpUserPwd)
{
	return CGoogleEntry::GetInstance()->GetUserPwd(lpUserPwd);
}